<?php
/*
 * kernel/object.console.php
 *
 * This code is distributed and used under the GNU GPL v2 License,
 * please, read file LICENSE, which is situated in root directory,
 * or in "LICENSE" directory with most acceptable translation for you
 *
 * 
 *
 * Copyright (C) 2010, Taras Kudla
 *
 */

define("_MAX_INPUT_BUFFER",128);

class gConsole extends gKernel {

    /**
     * Reads message from inupt, with message to output
     *
     * @param string $message
     * @return string
     */
    public function read($message=null){
        if($message!=null)
            print $message;
        $stdin = fopen('php://stdin', 'r');
        $buffer=fread($stdin,_MAX_INPUT_BUFFER);
        fclose($stdin);
        return trim($buffer);
    }

    /**
     * Writes message to output
     *
     * @param string $message
     */
    public function write($message){
        print $message;
    }

    /**
     * Writes message to output with new line character
     *
     * @param string $message
     */
    public function writeln($message){
        print $message."\n";
    }

    /**
     * Reads data from input with prompt message
     *
     * @param string $message
     * @return boolean
     */
    public function confirm($message=null){
        if($message!=null)
            print $message." [Y]: ";
        $stdin = fopen('php://stdin', 'r');
        $buffer=fread($stdin,_MAX_INPUT_BUFFER);
        fclose($stdin);
        $c=trim($buffer);
        return ( strtolower($c)!="y" || strtolower($c)!="yes")?false:true;
    }
    /*
     * NCURSES -----------------------------------------------------------------
     */
    



}